package com.liner;

import java.util.Arrays;

/**
 * @author 一条淡水鱼 ゆ
 * @Classname SelectionSort
 * @Description 选择排序
 * @Date 2023-04-01
 */
public class SelectionSort {
    public static void main(String[] args) {
        int[] array = BubbleSort.getInts();
        System.out.println(Arrays.toString(array));
        sort(array);
        System.out.println(Arrays.toString(array));

    }

    private static void sort(int[] array) {
        //对比次数
        int compareCount = 0;
        //交换次数
        int swapCount = 0;

        //记录排序开始前的时间值
        long startTime = System.currentTimeMillis();

        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                compareCount++;
                if (array[i] > array[j]) {
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                    swapCount++;
                }
            }
        }


        long endTime = System.currentTimeMillis();

        System.out.println("耗时:" + (endTime - startTime));
        System.out.println("对比次数:" + compareCount);
        System.out.println("交换次数:" + swapCount);
    }
}
